class Solution {
    List<List<Integer>> ret;
    List<Integer> path;

    public List<List<Integer>> subsets(int[] nums) {
        //策略一
        ret = new ArrayList<>();
        path = new ArrayList<>();
        dfs(nums, 0);
        return ret;
    }

    public void dfs(int[] nums, int pos) {
        if (pos >= nums.length) {
            //存储遍历到叶子结点的path路径
            ret.add(new ArrayList<>(path));
            return;
        }

        //选
        path.add(nums[pos]);
        dfs(nums, pos + 1);
        path.remove(path.size() - 1);//回溯 -> 恢复现场

        //不选(此时本层已恢复现场)
        dfs(nums, pos + 1);
    }
}